<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<button>关灯</button>
<script>
    const btn = document.querySelector('button');
    const bd = document.querySelector('body');
    btn.onclick = function () {
        if (btn.innerHTML === '关灯') {
            bd.style.backgroundColor = '#111';
            btn.innerHTML = '开灯';
        }
        else {
            bd.style.backgroundColor = '#fff';
            btn.innerHTML = '关灯';
        }
    }
</script>
</body>
</html>
